package com.henry.reader;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class SettingActivity extends Activity implements OnClickListener,
		OnTouchListener {

	private Map<Integer, int[]> drawableIds = new HashMap<Integer, int[]>();

	private View lastFocusview; 

	/*
	 * ������Ϣ
	 */
	private Button lyXwxx;

	/*
	 * �������
	 */
	private Button lyHdtd;

	/*
	 * ʵ����Ѷ
	 */
	private Button lySyzx;

	public boolean onTouch(View view, MotionEvent event) {
		lastFocusview.setBackgroundResource(drawableIds.get(lastFocusview
				.getId())[0]);
		if (event.getAction() == MotionEvent.ACTION_UP) {
			view.setBackgroundResource(drawableIds.get(view.getId())[0]);
		} else if (event.getAction() == MotionEvent.ACTION_DOWN)
			view.setBackgroundResource(drawableIds.get(view.getId())[1]);
		return false;
	}

	public void onClick(View v) {
		switch (v.getId()) {

		// ������Ϣ
		case R.id.ly_xwxx:
			Intent intentXwxx = new Intent(this, ActivityMain.class);
			startActivity(intentXwxx);
			break;

		// ʵ����Ѷ
		case R.id.ly_syzx:
			Intent intentSyzx = new Intent(this, SyzxActivity.class);
			startActivity(intentSyzx);
			break;

		default:
			break;
		}
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		find();
		bind();
	}

	/**
	 * ����Ԫ��
	 */
	private void find() {
		lyXwxx = (Button) findViewById(R.id.ly_xwxx);
		lyHdtd = (Button) findViewById(R.id.ly_hdtd);
		lySyzx = (Button) findViewById(R.id.ly_syzx);
	}

	/**
	 * ��Ԫ��
	 */
	private void bind() {
		lyXwxx.setOnClickListener(this);
		lyHdtd.setOnClickListener(this);
		lySyzx.setOnClickListener(this);

		lyXwxx.setOnTouchListener(this);
		lyHdtd.setOnTouchListener(this);
		lySyzx.setOnTouchListener(this);

		// ��ʼ����ť���

		drawableIds.put(R.id.ly_xwxx, new int[] { R.drawable.menu_01_off,
				R.drawable.menu_01_on });

		drawableIds.put(R.id.ly_hdtd, new int[] { R.drawable.menu_02_off,
				R.drawable.menu_02_on });

		drawableIds.put(R.id.ly_syzx, new int[] { R.drawable.menu_03_off,
				R.drawable.menu_03_on });

		lastFocusview = lySyzx;
	}

}
